package com.puman.houmu.puman.login;

import android.content.Intent;
import android.drm.DrmStore;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.puman.houmu.puman.R;
import com.puman.houmu.puman.Shouye.HomeActivity;

/**
 * Created by layne on 2017/8/4.
 */

public class loginActivity extends AppCompatActivity implements View.OnClickListener{

    public static final String TAG = "loginActivity";

    private EditText mobilePhone;
    private EditText password;
    private Button signupBtn;

    private Button forgetPwdBtn;
    private Button loginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        ininListence();
    }

    private void initView(){
        //隐藏系统自带导航
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null){
            actionBar.hide();
        }
        mobilePhone = (EditText) findViewById(R.id.mobilePhone);
        password = (EditText) findViewById(R.id.passWord);
        signupBtn = (Button) findViewById(R.id.signUpBtn);
        forgetPwdBtn = (Button) findViewById(R.id.forgetBtn);
        loginBtn = (Button) findViewById(R.id.login);
    }

    //设置监听器
    private void ininListence(){
        signupBtn.setOnClickListener(this);
        forgetPwdBtn.setOnClickListener(this);
        loginBtn.setOnClickListener(this);
    }

    //单机事件监听
    public void onClick(View v){
        if (v == signupBtn){
            signUp();
        } else if (v == forgetPwdBtn){
            forgetPassWord();
        } else if (v == loginBtn){
            login();
        }
    }

    private void login() {
        Log.d(TAG, "login: 11111111");
        final String user = "18912092868";//mobilePhone.getText().toString().trim();
        final String pwd = "123";//passWord.getText().toString().trim();
        if (TextUtils.isEmpty(user)
                || TextUtils.isEmpty(pwd)){
            Toast.makeText(loginActivity.this,"手机号或者密码不能为空",Toast.LENGTH_SHORT).show();
        } else if (user.length() != 11){
            Toast.makeText(loginActivity.this,"手机号格式不正确",Toast.LENGTH_SHORT).show();
        } else if (user.equals("18912092868")
                && pwd.equals("123")){
            Intent intent = new Intent();
            intent.setClass(loginActivity.this,HomeActivity.class);
            loginActivity.this.startActivity(intent);
        }
    }

    private void forgetPassWord() {
        Intent forGetIntent = new Intent();
        forGetIntent.setClass(loginActivity.this,ForgetPwdActivity.class);
        loginActivity.this.startActivity(forGetIntent);
    }

    private void signUp() {
        Intent signUpIntent = new Intent();
        signUpIntent.setClass(loginActivity.this,signUpActivity.class);
        loginActivity.this.startActivity(signUpIntent);
    }

}






















